<?php
namespace Admin\Controller;
use Think\Controller;
class GroupController extends CommonController {
    public function lists(){
        $list=D('group')->select();
        $this->assign('list',$list);
        $this->display();
    }
    public function add(){
        if(IS_POST){
           $_POST['rules']=implode(',',$_POST['rules']);
           $res=D('group')->add(i('post.'));
           if($res){
            $this->success('新增成功', 'lists');die;
            } else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置
                $this->error('新增失败');}die;
        }

        $parent=D('nav')->where('pid=0')->select();
        $child=D('rule')->select();
        $this->assign('parent',$parent);
        $this->assign('child',$child);
        $this->display();
    }
    public function edit(){
        $id=i('get.id');
        $list=D('group')->where("id=$id")->find();
        $list['rules']= explode(",", $list['rules']);
        //print_r($list);die;
        $this->assign('list',$list);
        $parent=D('nav')->where('pid=0')->select();
        $rule=D('rule')->relation(true)->select();
        print_r($rule);die;
        $child=D('rule')->select();
        $this->assign('parent',$parent);
        $this->assign('child',$child);
        $this->display();
    }
}